package org.jeecg.modules.foc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.foc.FocSpaceTreeDTO;
import org.jeecg.modules.foc.entity.FocSpace;
import org.jeecg.modules.foc.mapper.FocDeviceMapper;
import org.jeecg.modules.foc.mapper.FocSpaceMapper;
import org.jeecg.modules.foc.service.IFocSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Collection;
import java.util.List;

/**
 * @Description: 空间管理
 * @Author: jeecg-boot
 * @Date:   2025-01-10
 * @Version: V1.0
 */
@Service
public class FocSpaceServiceImpl extends ServiceImpl<FocSpaceMapper, FocSpace> implements IFocSpaceService {


    @Autowired
   private FocDeviceMapper focDeviceMapper;
    @Override
    public void  getSpaceTree(FocSpaceTreeDTO focSpaceTreeDTO) {
        //根据全局ID获取空间树结构
        QueryWrapper<FocSpace> queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent_guid",focSpaceTreeDTO.getGuid());
        List<FocSpace> list = this.list(queryWrapper);
        if (CollectionUtil.isEmpty(list)){
            return ;
        }
        List<FocSpaceTreeDTO> focSpaceTreeDTOS = BeanUtil.copyToList(list, FocSpaceTreeDTO.class);
        for (FocSpaceTreeDTO focSpace : focSpaceTreeDTOS) {
            //递归获取空间树结构
            getSpaceTree(focSpace);
            focSpaceTreeDTO.setChildren(focSpaceTreeDTOS);
        }
    }


}
